﻿using System.Windows;
using Baosight.Platform.Core.UI.Controls;
using System.Collections.Generic;
using Baosight.Platform.Core;
using Baosight.ZNH.ZMCommon;
using System.Windows.Threading;
using System;
using System.Windows.Controls;
using Baosight.ZNH.ZMCommon.ChildWindows;
using Baosight.Platform.Core.ServiceModel;

namespace Baosight.ZNH.ZMCL.UI.PopWindows
{
    /// <summary>
    /// 巡检路线新增和修改
    /// </summary>
    /// Title:InsertOrUpdateSercurityPath
    /// Service:ServiceZMCL91
    /// Copyright:Baosight Software LTD.co Copyright (c) 2011
    /// Company:上海宝信软件股份有限公司
    /// Author: 高强
    /// Version: 1.0
    /// History:
    ///       2011-6-30  高强   [创建]
    ///  
    public partial class InsertOrUpdateSercurityPath : EFViewCmes
    {
        private string actionType;//处理类型

        public InsertOrUpdateSercurityPath(string dialogType)
        {
            InitializeComponent();
            base.BeforeAction += OnBeforeAction;
            Init(dialogType);
        }

        /// <summary>
        /// 初始化父类EFViewCmesProperty的值，每次点击“确定”、“返回”时执行此方法，从新赋值
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnBeforeAction(object sender, EventArgs e)
        {
            EFViewCmesProperty _view = new EFViewCmesProperty();
            _view.DataFields = this.InsertPanel.GetChildObjects<EFDataField>(null, true);
            base.ViewProperty = _view;
        }

        /// <summary>
        /// 初始化页面数据
        /// </summary>
        private void Init(string type)
        {
            type = type == null ? "insert" : type.ToLower();

            switch (type)
            {
                case "insert":
                    this.actionType = "insert";
                    base.Mode = OperationMode.Insert;
                    break;
                case "update":
                    this.actionType = "update";
                    base.Mode = OperationMode.Update;
                    this.fdPathCode.IsReadOnly = true;
                    break;
                default:
                    break;
            }
        }

        /// <summary>
        /// 确定按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CommitClick(object sender, RoutedEventArgs e)
        {
            base.OnCommitButtonClick("ZMCL91", sender, e);
        }

        /// <summary>
        /// 取消按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CancelClick(object sender, RoutedEventArgs e)
        {
            CmesWindows _window = this.Parent as CmesWindows;
            _window.DialogResult = false;
            _window.Close();
        }

        /// <summary>
        /// 重写了确定按钮执行事件的回调方法
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public override void DoCommitCompleted(object sender, DoWorkCompletedEventArgs e)
        {

            EIInfo inInfo = e.EIInfo;
            if (inInfo.Status == -1)
            {
                this.TempButtonOpen(true);
                this.OnCommitMessagePopup(inInfo);//操作失败，消息提醒
            }
            else
            {
                if ("insert".Equals(actionType))
                {
                    NotifyViewDataChanged(e.EIInfo.Get("fdPathCode").ToString());//通知重新获得巡检路线编号
                }
                EFWindow window = this.Parent as EFWindow;
                window.DialogResult = true;
                window.Close();
            }
        }
    }
}
